function lta = ltriasc(m, p)
% ltriasc  - ASCII form of a lower triangle matrix (for Mx)
%
% FORMAT:       lta = ltriasc(m [, p])
%
% Input fields:
%
%       m           double matrix
%       p           optional precision (default: 8)
%
% Output fields:
%
%       lta         ASCII form of lower triangle matrix

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 1 || ...
   ~isa(m, 'double') || ...
   ~isreal(m) || ...
    isempty(m) || ...
    ndims(m) ~= 2
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid matrix argument supplied.' ...
    );
end
if nargin < 2 || ...
   ~isa(p, 'double') || ...
   ~isreal(p) || ...
    numel(p) ~= 1 || ...
    isinf(p) || ...
    isnan(p) || ...
    p < 1 || ...
    p > 15
    pstr = ' %11.6f';
else
    pstr = sprintf(' %%%d.%df', ceil(p + 5), floor(p));
end

% initialize cell array
rc = size(m, 1);
cc = size(m, 2);
lta = cell(1, rc);

% iterate over rows
for rc = 1:rc
    
    % build row
    lta{rc} = sprintf(pstr, m(rc, 1:min(cc, rc)));
end

% build output
lta = gluetostring(lta, char(10));
